package com.ganee.agora.view

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProviders
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.braintreepayments.api.dropin.DropInActivity
import com.braintreepayments.api.dropin.DropInRequest
import com.braintreepayments.api.dropin.DropInResult
import com.ganee.agora.R
import com.ganee.agora.manager.Settings
import com.ganee.agora.viewmodel.SettingsViewModel
import com.ganee.baselib.arouter.Constance
import com.ganee.baselib.mvvmlibrary.base.BaseActivity
import kotlinx.android.synthetic.main.activity_settings.*
import kotlinx.android.synthetic.main.toolbar_profile.*

//设置页面
@Route(path = Constance.ACTIVITY_URL_SETTINGS)
class SettingsActivity : BaseActivity<SettingsViewModel>(),View.OnClickListener {

    override fun getViewModel(): SettingsViewModel {
        return ViewModelProviders.of(this@SettingsActivity).get(SettingsViewModel::class.java)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_settings)
        toolbarTitle.text = "Settings"
        toolbarRight.visibility = View.GONE

        toolbarCancel.setOnClickListener(this)
        event_ll.setOnClickListener(this)
        ll_video.setOnClickListener(this)
        ll_scan.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v!!.id){
            R.id.toolbarCancel -> {
                finish()
            }
            R.id.event_ll -> {
//                val token = "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiJleUowZVhBaU9pSktWMVFpTENKaGJHY2lPaUpGVXpJMU5pSXNJbXRwWkNJNklqSXdNVGd3TkRJMk1UWXRjMkZ1WkdKdmVDSXNJbWx6Y3lJNklrRjFkR2g1SW4wLmV5SmxlSEFpT2pFMU56azBNakkzTmpJc0ltcDBhU0k2SWpOak9EVTFOV0ZsTFdFMll6a3ROREl6WVMwNFlXSmxMV1ZrTlRWa05EUXpaVE5rWkNJc0luTjFZaUk2SW5SM2Q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jb20vdHd3dmc4OTYzdG0yNjN0ZCJ9LCJ0aHJlZURTZWN1cmVFbmFibGVkIjp0cnVlLCJwYXlwYWxFbmFibGVkIjp0cnVlLCJwYXlwYWwiOnsiZGlzcGxheU5hbWUiOiJhZ29yYSIsImNsaWVudElkIjpudWxsLCJwcml2YWN5VXJsIjoiaHR0cDovL2V4YW1wbGUuY29tL3BwIiwidXNlckFncmVlbWVudFVybCI6Imh0dHA6Ly9leGFtcGxlLmNvbS90b3MiLCJiYXNlVXJsIjoiaHR0cHM6Ly9hc3NldHMuYnJhaW50cmVlZ2F0ZXdheS5jb20iLCJhc3NldHNVcmwiOiJodHRwczovL2NoZWNrb3V0LnBheXBhbC5jb20iLCJkaXJlY3RCYXNlVXJsIjpudWxsLCJhbGxvd0h0dHAiOnRydWUsImVudmlyb25tZW50Tm9OZXR3b3JrIjp0cnVlLCJlbnZpcm9ubWVudCI6Im9mZmxpbmUiLCJ1bnZldHRlZE1lcmNoYW50IjpmYWxzZSwiYnJhaW50cmVlQ2xpZW50SWQiOiJtYXN0ZXJjbGllbnQzIiwiYmlsbGluZ0FncmVlbWVudHNFbmFibGVkIjp0cnVlLCJtZXJjaGFudEFjY291bnRJZCI6ImFnb3JhIiwiY3VycmVuY3lJc29Db2RlIjoiVVNEIn0sIm1lcmNoYW50SWQiOiJ0d3d2Zzg5NjN0bTI2M3RkIiwidmVubW8iOiJvZmYifQ=="
//                val dropInRequest = DropInRequest()
//                        .clientToken(token) as DropInRequest
//                startActivityForResult(dropInRequest.getIntent(this), 110)
            }
            R.id.ll_scan -> {
//                ARouter.getInstance().build(Constance.ACTIVITY_URL_SCAN_QRCODE).navigation()
            }

            R.id.ll_video -> {
//                ARouter.getInstance().build(Constance.ACTIVITY_URL_VIDEO_PLAYER).navigation()
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 110) {
            if (resultCode == RESULT_OK) {
                val result = data!!.getParcelableExtra (DropInResult.EXTRA_DROP_IN_RESULT) as DropInResult
                // use the result to update your UI and send the payment method nonce to your server
            } else if (resultCode == RESULT_CANCELED) {
                // the user canceled
            } else {
                // handle errors here, an exception may be available in
                val error = data!!.getSerializableExtra (DropInActivity.EXTRA_ERROR) as Exception
            }
        }
    }
}
